package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.FeedbackReq;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DifyApp;
import com.ruoyi.system.service.IDifyAppService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * Dify应用配置Controller
 * 
 * @author xiaoyilala
 * @date 2025-07-23
 */
@RestController
@RequestMapping("/system/difyApp")
public class DifyAppController extends BaseController
{
    @Autowired
    private IDifyAppService difyAppService;

    /**
     * 查询Dify应用配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:difyApp:list')")
    @GetMapping("/list")
    public TableDataInfo list(DifyApp difyApp)
    {
        startPage();
        List<DifyApp> list = difyAppService.selectDifyAppList(difyApp);
        return getDataTable(list);
    }

    /**
     * 导出Dify应用配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:difyApp:export')")
    @Log(title = "Dify应用配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DifyApp difyApp)
    {
        List<DifyApp> list = difyAppService.selectDifyAppList(difyApp);
        ExcelUtil<DifyApp> util = new ExcelUtil<DifyApp>(DifyApp.class);
        util.exportExcel(response, list, "Dify应用配置数据");
    }

    /**
     * 获取Dify应用配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:difyApp:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(difyAppService.selectDifyAppById(id));
    }

//    /**
//     * 新增Dify应用配置
//     */
//    @PreAuthorize("@ss.hasPermi('system:difyApp:add')")
//    @Log(title = "Dify应用配置", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody DifyApp difyApp)
//    {
//        return toAjax(difyAppService.insertDifyApp(difyApp));
//    }



    /**
     * 新增Dify应用配置
     */
    @PreAuthorize("@ss.hasPermi('system:difyApp:add')")
    @Log(title = "Dify应用配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DifyApp difyApp)
    {
        return toAjax(difyAppService.addDifyApp(difyApp));
    }




    /**
     * 修改Dify应用配置
     */
    @PreAuthorize("@ss.hasPermi('system:difyApp:edit')")
    @Log(title = "Dify应用配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DifyApp difyApp)
    {
        return toAjax(difyAppService.updateDifyApp(difyApp));
    }

    /**
     * 删除Dify应用配置
     */
    @PreAuthorize("@ss.hasPermi('system:difyApp:remove')")
    @Log(title = "Dify应用配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(difyAppService.deleteDifyAppByIds(ids));
    }



    @GetMapping("/difyList")
    public AjaxResult defyList(){
        return AjaxResult.success(difyAppService.selectDifyList());
    }



    @PostMapping("/feedback")
    public AjaxResult feedback(@RequestBody FeedbackReq feedbackReq){
        difyAppService.feedback(feedbackReq);

        return AjaxResult.success();
    }


    @GetMapping("/getFeedback")
    public AjaxResult getFeedback(){
        return AjaxResult.success(difyAppService.getFeedback());
    }


}
